<!--
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-26 20:04:00
 * @LastEditors: dedeye
 * @LastEditTime: 2020-02-26 23:16:51
 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ADMIN__/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__ADMIN__/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="editForm">
    {:token('mykey')}
    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" lay-reqtext="账号不能为空" placeholder="请输入账号" value="" class="layui-input">
            <tip>填写自己管理账号的名称，用于用户登录</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="nickname" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" class="layui-input">
            <tip>填写自己昵称，用于前端显示</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" class="layui-input">
            <tip>填写自己昵称，用于前端显示</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="repassword" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请确认密码" class="layui-input">
            <tip>填写自己登录密码</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="正常|禁用" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="__ADMIN__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            const param = data.field;
            if(param.status && param.status == 'on') {
                param.status = 1;
            } else {
                param.status = 0;
            }
            $.ajax({
                url: '/admin/user/add',
                data: param,
                method: 'post',
                success: function (res) {
                    if(res.code < 0) {
                        layer.msg(res.msg, {icon: 5,time: 500,shade: 0.1});
                        return false;
                    }
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 500,
                        shade: 0.1
                    }, function () {
                        closeThis(true)
                    });
                }
            })
            return false;
        });

        function closeThis(re = false)
        {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            if(re)
                parent.$('#isReload').val('yes');
            parent.layer.close(iframeIndex);
        }
    });
</script>
</body>
</html>